<?php
	class PageView {
		
		private $m_title = NULL;
		private $m_cssTags = array();
		private $m_metaTags = array();
		private $m_scriptTags = array();
		private $m_body = NULL;
		private $m_charset = NULL;
		
		public function __construct($charset = "UTF-8"){
			
			$this->m_charset = $charset;
		}
		
		//Lägger till cssdokument till sidan
		public function AddStylesheet($newStyleSheet){
			$this->m_cssTags[] = "<link href='$newStyleSheet' rel='StyleSheet' type='text/css' />";
		}
		//Lägger till metataggar till sidan
		public function AddMetaTags($name, $content){
			$this->m_metaTags[] = "<name='$name' content='$content' />";
		}
		//Lägger till scriptdokument till sidan
		public function AddScript ($newScript){
			$this->m_scriptTags[] = "<script src='$newScript'></script>";
		}
		//Skriver ut Meta- and css taggar
		private function RenderHeadTags() {
		    
      		$end = "\n";
			
		    $retValue = "";
		    foreach($this->m_metaTags as $tag) {
		      $retValue .= $tag . "$end            ";
		    }
			foreach($this->m_cssTags as $tag) {
		      $retValue .= $tag . "$end            ";
		    }
		    return $retValue;
	  	}
		//Skriver ut scripttaggar
		private function RenderScriptTags() {
		    
      		$end = "\n";
			
		    $retValue = "";
		    foreach($this->m_scriptTags as $tag) {
		      $retValue .= $tag . "$end            ";
		    }
		    return $retValue;
	  	}
		//Skapar ett HTML-document
		public function GetHTMLPage($title, $body){
			$head = $this->RenderHeadTags();
			$script = $this->RenderScriptTags();
			return "
<!DOCTYPE html>
	<html>
	    <head>
	        <title>$title</title>
	        <meta charset=$this->m_charset' />
	        $head
	    </head>
	    <body>
  	 		$body
	  		$script
	  	</body>
	</html>";
		}
		//Skapar ett XHTML-document
		public function GetXHTMLPage($title, $body) {
			$head = $this->RenderHeadTags();
			$script = $this->RenderScriptTags();
			return "
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
	<html xmlns='http://www.w3.org/1999/xhtml'>
	    <head>
	    	<title>$title</title>
	   		<meta http-equiv='content-type' content='text/html; charset=$this->m_charset' />
	   		$head
		</head>
	  	<body>
  	 		$body
	  		$script
	  	</body>
	</html>";
		}
	}